Imports System.Data

Partial Class Usercontrols_ControlPanel_UserActivity
    Inherits UserControlBase

#Region " Enums, Memebers and Properties "



#End Region

#Region " Page Events "

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Me.Page.IsPostBack = False Then
            LoadUsersOnline()
            LoadNewestUsers()
        End If

    End Sub

#End Region

#Region " Save Data "



#End Region

#Region " Load Data "

    Private Sub LoadUsersOnline()
        Dim ListUser As MembershipUser
        Dim UserList As New StringBuilder

        For Each ListUser In Membership.GetAllUsers
            If ListUser.IsOnline Then
                UserList.Append(String.Format("<a href=""{0}.aspx?pid=cp_profileview&userid={1}"">{1}</a>, ", AppPage, ListUser.UserName))
            End If
        Next

        If UserList.Length > 0 Then
            If Right(UserList.ToString, 2) = ", " Then
                UserList.Length = UserList.Length - 2
            End If
        End If

        Me.uxUsersOnelineListLabel.Text = UserList.ToString
        Me.uxVisitorsOnlineLabel.Text = String.Format("{0} <b>{1}</b>", Resources.Resource.Visitors.ToString, Application("ActiveUsers"))
        Me.uxUsersOnlineLabel.Text = String.Format("{0} <b>{1}</b>", Resources.Resource.Members.ToString, Membership.GetNumberOfUsersOnline.ToString)
        Me.uxTotalUserCountLabel.Text = String.Format("{0} <b>{1}</b>", Resources.Resource.Total.ToString, Membership.GetNumberOfUsersOnline + Application("ActiveUsers"))

    End Sub

    Private Sub LoadNewestUsers()
        Dim MU As New MembershipUtility
        Dim DS As New DataSet
        Dim DT As New DataTable
        Dim DV As New DataView
        Dim UserList As New StringBuilder
        Dim DVRow As DataRowView
        Dim Counter As Integer = 0

        DS = MU.GetAllUsers

        DT = DS.Tables(0)

        DV.Table = DT

        DV.Sort = "creationdate desc"

        For Each DVRow In DV
            If Counter < 5 Then
                UserList.Append(String.Format("<a href=""{0}.aspx?pid=cp_profileview&userid={1}"">{1}</a>, ", AppPage, DVRow("UserName")))
                Counter += 1
            Else
                Exit For
            End If
        Next

        If UserList.Length > 0 Then
            If Right(UserList.ToString, 2) = ", " Then
                UserList.Length = UserList.Length - 2
            End If
        End If

        Me.uxNewestUsersListLabel.Text = UserList.ToString

    End Sub

#End Region

#Region " Form Controls Events "

#End Region

#Region " Helpers and Methods "

#End Region

End Class
